package ups.Database;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import ups.Common.Port;
import ups.Common.Port.Map;

/**
 * @author scanfield
 * 
 */
public class PortDatabase extends Database {
	
	private String PORT_TABLE 		= "ports";
	private String PORT_NAME_KEY 	= "name";
	private String PORT_MAP_KEY 	= "map";
	private String PORT_X_KEY 		= "x";
	private String PORT_Y_KEY 		= "y";
	
	public PortDatabase(String hostName, int portNum, String databaseName, String username, String password) {
		super(hostName, portNum, databaseName, username, password);
	}

	public boolean exists() {
		return false;
	}
	
	public void create() {
		
	}
	
	public void setPortNames() {
		
	}
	
	public ArrayList<Port> getPorts() {
		ArrayList<Port> ports = new ArrayList<Port>();
		ResultSet rs = super.get( PORT_TABLE );
		try {
			while( rs.next() )
			{
				Map whichMap;
				if( rs.getString( PORT_MAP_KEY ).equals( "0" )) {
					whichMap = Map.Seattle;
				} else {
					whichMap = Map.Tacoma;
				}
				Port port = new Port( 	rs.getString( PORT_NAME_KEY ),
										whichMap,
										rs.getInt	( PORT_X_KEY	),
										rs.getInt	( PORT_Y_KEY	));
				ports.add( port );
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return ports;
	}
	
	
	
}
